home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / msgnfmt.c < prev    next >
C/C++ Source or Header  |  1996-08-29  |  8KB  |  291 lines

  1. /*
  2. *       MsgNFmt.c
  3. *
  4. * Prints a message in network format to blind target.
  5. */
  6. /*
  7. *       history
  8. *
  9. * 89Apr27 HAW Bad interaction of routemail and Other Recipients
  10. * 89Feb05 HAW  Created.
  11. */
  12. #include "ctdl.h"
  13. /*
  14. *       contents
  15. *
  16. * prNetStyle()    sends a msg in net format.
  17. * NetCC()     write out Other Recipient fields
  18. * NetOverride()   write out recipient override fields
  19. */
  20. extern logBuffer logTmp;  /* Person buffer  */
  21. extern int       callSlot;
  22. extern NetBuffer netBuf, netTemp;
  23. extern SListBase MailForward;
  24. extern CONFIG    cfg; /* Lots an lots of variables    */
  25. extern MessageBuffer   msgBuf;
  26. /* void NetOverride(); */
  27. char   PrTransmit = TRUE; /* TRUE if writing to comm line */
  28. /* FALSE if writing to disk */
  29. int  (*NetCharSource)(void) = getNetChar;
  30. static char Overrode;
  31. #define WriteCC     WriteField
  32. #define NetOverride   WriteField
  33. void WriteField();
  34. #define CC    0
  35. #define OVERRIDE  1
  36. #define NONE    2
  37. char FieldType;
  38. /*
  39. * NetPrintTarget allows us to blindly choose what to do with
  40. * the output.
  41. */
  42. void (*NetPrintTarget)(char *format, ...);
  43. static char *GoingFor;
  44. /*
  45. * prNetStyle()
  46. *
  47. * This sends a msg in NET format.  Target can be either disk or comm line.
  48. */
  49. void prNetStyle(int NotMsgBase, int (*method)(int c), char GetMsg,
  50. char *TargetSystem)
  51.   {
  52.   ForwardMail *address;
  53.   long  val;
  54.   int   c;
  55.   int   (*SourceFn)(void);
  56.   char  *rover;
  57.   extern char inNet;
  58.   GoingFor = TargetSystem;
  59.   /*
  60.   * Typically, we'll be getting a message to transmit from the
  61.   * message base.  However, sometimes we don't.  In those very rare
  62.   * cases we'll use the NetCharSource POINTER to find out where
  63.   * to get the stuff.  This defaults to getNetChar, which is used
  64.   * to read virtual room messages, but is also occasionally used to
  65.   * read STadel routemail files to convert them to our route mail
  66.   * files.
  67.   */
  68.   SourceFn = (NotMsgBase == 0) ? getMsgChar : NetCharSource;
  69.   /* fill in local node in origin fields if local message: */
  70.   if (!msgBuf.mborig[ 0])
  71.   strCpy(msgBuf.mborig,  cfg.nodeId + cfg.codeBuf  );
  72.   if (!msgBuf.mboname[0])
  73.     {
  74.     strCpy(msgBuf.mboname, cfg.nodeName + cfg.codeBuf);
  75.     strCpy(msgBuf.mbdomain, cfg.nodeDomain + cfg.codeBuf);
  76.     
  77.     }
  78.   /* Convert # to 8-bit Citadel style for compatibility   */
  79.   if (!msgBuf.mbsrcId[0])
  80.     {
  81.     val = atol(msgBuf.mbId);
  82.     sPrintf(msgBuf.mbsrcId, "%ld %ld",
  83.     (val & 0xFFFF0000l) >> 16, val & 0xFFFFl);
  84.     
  85.     }
  86.   /* send header fields out: */
  87.   if (msgBuf.mbauth[ 0])  (*NetPrintTarget)("A%s", msgBuf.mbauth );
  88.   if (msgBuf.mbdate[ 0])  (*NetPrintTarget)("D%s", msgBuf.mbdate );
  89.   if (msgBuf.mbtime[ 0])  (*NetPrintTarget)("C%s", msgBuf.mbtime );
  90.   (*NetPrintTarget)("N%s", msgBuf.mboname);
  91.   (*NetPrintTarget)("O%s", msgBuf.mborig );
  92.   if (msgBuf.mbdomain[0])
  93.   (*NetPrintTarget)("X%s", msgBuf.mbdomain);
  94.   if (msgBuf.mbroom[ 0])  (*NetPrintTarget)("R%s", msgBuf.mbroom );
  95.   (*NetPrintTarget)("S%s", msgBuf.mbsrcId);
  96.   if (msgBuf.mbOther[0])  (*NetPrintTarget)("P%s", msgBuf.mbOther);
  97.   FieldType = CC;
  98.   RunList(&msgBuf.mbCC, WriteCC); /* write out Who Else fields */
  99.   Overrode = FALSE;
  100.   /*
  101.   * this if handles a piece of user-generated route mail
  102.   * in this situation there are no overrides and they must be
  103.   * generated from the mbCC list.
  104.   */
  105.   if (!PrTransmit && inNet == NON_NET)
  106.     {
  107.     /*
  108.     * If mbOverride has stuff, this is caused by forwarding set up
  109.     * by one or more of the recipients of the mail.  This may
  110.     * include mail initially locally forwarded ...
  111.     */
  112.     if (GetFirst(&msgBuf.mbInternal) == NULL)
  113.     RunList(&msgBuf.mbCC, NetCC);
  114.     else
  115.     RunList(&msgBuf.mbInternal, NetCC);
  116.     
  117.     }
  118.   /*
  119.   * this else translates to route mail being written to disk caused by
  120.   * mail forwarding during a network session -- that's the only case
  121.   * that'll satisfy this if. In this case the only override generation can
  122.   * come from the overrides already in place -- they are the only
  123.   * recipients on this system, so only they can generate a mail forwarding
  124.   * request.
  125.   */
  126.   else if (!PrTransmit && inNet != NON_NET)
  127.     {
  128.     RunList(&msgBuf.mbOverride, NetCC);
  129.     RunList(&msgBuf.mbInternal, NetCC);
  130.     
  131.     }
  132.   /*
  133.   * this else translates to network transmission of "normal" mail --
  134.   * that is, mail coming from the message base and therefore not
  135.   * bearing overrides.  Any overrides must therefore be generated
  136.   * from the Who Else list.
  137.   */
  138.   else if (!NotMsgBase && PrTransmit && inNet != NON_NET)
  139.     {
  140.     RunList(&msgBuf.mbCC, NetCC);
  141.     
  142.     }
  143.   /*
  144.   * this else covers route mail about to be transmitted on the net.
  145.   * In this case the override fields already exist (from the originating
  146.   * system) so we just write them out, and everything's cool.
  147.   */
  148.   else if (NotMsgBase && PrTransmit && inNet != NON_NET)
  149.     {
  150.     FieldType = OVERRIDE;
  151.     RunList(&msgBuf.mbOverride, NetOverride);
  152.     
  153.     }
  154.   if (msgBuf.mbaddr[ 0] && (!PrTransmit || Overrode))
  155.     {
  156.     (*NetPrintTarget)("Q%s", msgBuf.mbaddr );
  157.     
  158.     }
  159.   /*
  160.   * Basically, only do possible 'T' transformations if we're not outgoing
  161.   * route mail and we're not writing route mail to disk generated by
  162.   * incoming mail hitting a person with mail forwarding on.
  163.   */
  164.   if (!(NotMsgBase && PrTransmit && inNet != NON_NET))
  165.     {
  166.     /*
  167.     * we use this control structure for backward compatability:
  168.     * systems which do not recognize the 'w' field of net messages.
  169.     */
  170.     if (Overrode)
  171.       {
  172.       if (msgBuf.mbto[  0])
  173.       (*NetPrintTarget)("T%s", msgBuf.mbto   );
  174.       if (SearchList(&msgBuf.mbInternal, msgBuf.mbto) == NULL)
  175.         {
  176.         if (msgBuf.mbaddr[0])
  177.         sPrintf(msgBuf.mbtext, "%s@%s", msgBuf.mbto, msgBuf.mbaddr);
  178.         else
  179.         strCpy(msgBuf.mbtext, msgBuf.mbto);
  180.         NetCC(msgBuf.mbtext);
  181.         
  182.         }
  183.       
  184.       }
  185.     else
  186.       {
  187.       if (msgBuf.mbto[   0])
  188.         {
  189.         address = SearchList(&MailForward, msgBuf.mbto);
  190.         (*NetPrintTarget)("T%s",
  191.         (address != NULL && strCmpU(address->System, GoingFor)
  192.         == SAMESTRING) ? address->Alias : msgBuf.mbto);
  193.         
  194.         }
  195.       else (*NetPrintTarget)("T%s", msgBuf.mbto);
  196.       
  197.       }
  198.     
  199.     }
  200.   else if (msgBuf.mbto[0]) (*NetPrintTarget)("T%s", msgBuf.mbto);
  201.   FieldType = NONE;
  202.   RunList(&msgBuf.mbForeign, WriteField);
  203.   /* send message text proper: */
  204.   (*method)('M');
  205.   if (GetMsg)
  206.     {
  207.     do
  208.       {
  209.       c = (*SourceFn)();
  210.       if (c=='\n')  c='\r';
  211.       if (!(*method)(c)) break;
  212.       
  213.       }
  214.     while (c && c != -1);
  215.     
  216.     }
  217.   else
  218.     {
  219.     for (rover = msgBuf.mbtext; *rover; rover++)
  220.     (*method)(*rover);
  221.     (*method)(0);
  222.     
  223.     }
  224.   
  225.   }
  226. /*
  227. * NetCC()
  228. *
  229. * This function is used to write out Other Recipient fields and sometimes
  230. * to write override fields (only when system origin is this system, not
  231. * another, however).
  232. */
  233. void NetCC(char *d)
  234.   {
  235.   ForwardMail *address;
  236.   label person;
  237.   char  system[(2 * NAMESIZE) + 2];
  238.   switch (SepNameSystem(d, person, system, &netTemp))
  239.     {
  240.     case IS_SYSTEM:
  241.     if (strCmpU(system, GoingFor) == SAMESTRING ||
  242.     strCmpU(LocalName(system), GoingFor) == SAMESTRING)
  243.       {
  244.       Overrode = TRUE;
  245.       (*NetPrintTarget)("w%s", person);
  246.       
  247.       }
  248.     break;
  249.     case NOT_SYSTEM:  /* forward to this system??? */
  250.     if ((address = SearchList(&MailForward, person)) != NULL &&
  251.     strCmpU(address->System, GoingFor) == SAMESTRING)
  252.       {
  253.       Overrode = TRUE;
  254.       (*NetPrintTarget)("w%s", address->Alias);
  255.       
  256.       }
  257.     break;
  258.     
  259.     }
  260.   
  261.   }
  262. #ifdef OLD_STYLE
  263. /*
  264. * WriteCC()
  265. *
  266. * This function is used to write out a 'W' field.
  267. */
  268. static void WriteCC(char *d)
  269.   {
  270.   (*NetPrintTarget)("W%s", d);
  271.   
  272.   }
  273. /*
  274. * NetOverride()
  275. *
  276. * This function is used to write out recipient override fields ('w').
  277. */
  278. static void NetOverride(char *d)
  279.   {
  280.   (*NetPrintTarget)("w%s", d);
  281.   
  282.   }
  283. #else
  284. #endif
  285. void WriteField(char *d)
  286.   {
  287.   (*NetPrintTarget)((FieldType == OVERRIDE) ? "w%s" :
  288.   (FieldType == CC) ? "W%s" : "%s", d);
  289.   
  290.   }
  291.